package com.credit.jumu.calculator.activity;

import android.content.Intent;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.credit.jumu.calculator.R;
import com.credit.jumu.calculator.base.BaseActivity;
import com.credit.jumu.calculator.utils.CalculatorUtil;
import com.credit.jumu.calculator.utils.LogUtils;
import com.credit.jumu.calculator.utils.StringHandleUtil;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

/**
 * Created by Administrator on 2017/11/23/023.
 */
@EActivity(R.layout.activity_car_result)
public class CarResultActivity extends BaseActivity {
	@ViewById
	TextView barheight, money1, money2, money3, fristNeed, everyNeed, allMoneyCar;


	double carallmoneyd;//总价
	double fristmoneyd;//首付比例
	double needyeard;//还款年限
	double carlilvd;//贷款利率
	double seatnumberd;//车座量
	double allXian;//所有的险
	String ccsys;//车船使用税

	@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
	@AfterViews
	public void initView() {
		Intent intent = getIntent();
		if (null == intent) {
			this.finish();
			return;
		}
		carallmoneyd = (intent.getDoubleExtra("carallmoneyd", 0)) * 10000;
		fristmoneyd = intent.getDoubleExtra("fristmoneyd", 0);
		needyeard = intent.getDoubleExtra("needyeard", 0);
		carlilvd = intent.getDoubleExtra("carlilvd", 0);
		seatnumberd = intent.getDoubleExtra("seatnumberd", 0);
		ccsys = intent.getStringExtra("ccsys");
		allXian = intent.getDoubleExtra("allXian", 0);
		RelativeLayout.LayoutParams Params1 = (RelativeLayout.LayoutParams) barheight.getLayoutParams();
		Params1.height = getNavigationBarHeight();
		barheight.setLayoutParams(Params1);
		toAllWindow();
		setData();
	}

	public void setData() {
		money1.setText(StringHandleUtil.toOnlyHavaTwo(carallmoneyd / (1.17) * 0.1) + "");
		money2.setText(StringHandleUtil.toOnlyHavaTwo(StringHandleUtil.toInt(ccsys)));
		money3.setText(seatnumberd < 6 ? "950.00"+ "" : "1100.00" + "");
		double allTax = StringHandleUtil.toInt(money1.getText().toString()) + StringHandleUtil.toInt(money2.getText().toString())
				+ StringHandleUtil.toInt(money3.getText().toString()) + 500;//自然
		fristNeed.setText(StringHandleUtil.toOnlyHavaTwo((carallmoneyd * fristmoneyd / 100) + allXian + allTax));

		double every = CalculatorUtil.getPerMonthPrincipalInterest(carallmoneyd * (1 - (fristmoneyd / 100)), carlilvd / 100, (int) (needyeard * 12));
		everyNeed.setText(every + "");
		allMoneyCar.setText(StringHandleUtil.toOnlyHavaTwo(every * needyeard * 12 + ((carallmoneyd * fristmoneyd / 100) + allXian + allTax)));
	}

	@Click(R.id.back)
	public void backClick() {
		this.finish();
	}
}
